<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('管理')" />
</head>
<body class="hold-transition skin-blue sidebar-mini layout-boxed">
<div class="wrapper">
    <th:block th:include="include :: headbar" />
    <th:block th:include="include :: sidebar" />
    <div class="content-wrapper">
        <section class="content-header">
            <h1>&nbsp;</h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">系统管理</a></li>
                <li class="active">管理</li>
            </ol>
        </section>
        <section class="content">
            <div class="box box-solid">
                <form class="box-header with-border form-inline" id="form">
                    <input type="text" class="form-control input-sm" placeholder="名称" name="">
                    <button type="button" class="btn btn-success btn-sm btn-flat" onclick="$.table.search('form')"><i class="fa fa-search"></i> 搜索</button>
                </form>
                <div class="box-body">
                    <div class="btn-group-sm form-inline" id="toolbar" notice="group">
                        <button type="button" class="btn btn-success btn-sm btn-flat" onclick="$.operate.add()"><i class="fa fa-plus"></i> 添加</button>
                        <button type="button" class="btn btn-primary btn-sm btn-flat" onclick="$.operate.edit()"><i class="fa fa-edit"></i> 修改</button>
                        <button type="button" class="btn btn-danger btn-sm btn-flat" onclick="$.operate.remove()"><i class="fa fa-remove"></i> 删除</button>
                    </div>
                    <table id="bootstrap-table" data-mobile-responsive="true"></table>
                </div>
            </div>
        </section>
    </div>
    <th:block th:include="include :: copyright" />
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = "/system/notice";
    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + '/add',
            removeUrl: prefix + '/remove',
            updateUrl: prefix + '/edit/{id}',
            sortName: "",
            uniqueId: 'noticeId',
            modalName: "",
            modalWidth: 350,
            modalHeight: 400,
            columns: [
                { radio: true },
                { title: "序号", formatter: function (value, row, index) { return $.table.serialNumber(index); }},
                { field: 'noticeName', title: '名称' },
                { title: '状态', align: 'center', formatter: statusFormatter }
			]
        };
        $.table.init(options);
    });

    function statusFormatter(value, row, index) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-lg\" onclick="disable(\'' + row.noticeId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-lg\" onclick="enable(\'' + row.noticeId + '\')"></i> ';
        }
    }

    function disable(noticeId) {
        $.post(prefix + "/changeStatus", { "noticeId": noticeId, "status": 0 }, function(resp){
            $.table.refresh();
        });
    }

    function enable(noticeId) {
        $.post(prefix + "/changeStatus", { "noticeId": noticeId, "status": 1 }, function(resp){
            $.table.refresh();
        });
    }
</script>
</body>
</html>
